<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>新建任务</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">任务编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" placeholder="请输入" readonly autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>任务名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>任务类别</label>
                        <div class="layui-input-block">
                            <select id="type" name="type" lay-filter="type" ></select>
                            <p class="error" id="type_error" style="margin: 0;"></p>
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-hide" id="type_bid">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="bidid" class="layui-input bidid" onclick="openPage('../public/choose_bid.php?dom=bidid','80%','80%')">
                            <div class="choose_div" id="bidid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_bid.php?dom=bidid','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-hide" id="type_engin">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="enginid" class="layui-input enginid" onclick="openPage('../public/choose_engin.php?dom=enginid','80%','80%')">
                            <div class="choose_div" id="enginid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_engin.php?dom=enginid','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>执行人</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=zhier&type=user&single=2', '770px', '490px');"></div>
                                <div class="tanxiannei" id="zhier"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=zhier&type=user&single=2', '770px', '490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="zhier_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>优先级</label>
                        <div class="layui-input-block">
                            <select id="youxian" name="youxian" lay-filter="youxian" ></select>
                            <p class="error" id="youxian_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">计划开始时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="planstartdt" id="planstartdt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymdhi">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">计划结束时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="planenddt" id="planenddt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymdhi">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">任务描述</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">关联单据</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="flowrelas" class="layui-input flowrelas" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');">
                            <div class="choose_div" id="flowrelas" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>


    $("#commentForm").validate({
        rules: {
            name: {required: true},
        },
        messages:{
            name: {required: "请输入"},
        }
    });


    var jietype;
    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_task_add}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;

                $("#number").val(data.number)

                var youxian_str = '<option value="">请选择</option>';
                var youxian = res.data.youxian;
                for (var key in youxian){
                    youxian_str += '<option value="'+youxian[key]+'">'+youxian[key]+'</option>';

                }
                $("#youxian").html(youxian_str);

                var type_str = '<option value="">请选择</option>';
                var type = res.data.type;
                for (var key in type){
                    type_str += '<option value="'+key+'">'+type[key]+'</option>';
                }
                $("#type").html(type_str);

                public_upload_file_load('upload_files');
                render_date();
                render_from();
            }
        });


        form.on('select(type)', function(data){
            if(data.value == ''){
                $('#type_error').show().text('请选择');
                $('#type_error').parent().find('input').addClass('select_error');
            }else{
                $('#type_error').hide();
                $('#type_error').parent().find('input').removeClass('select_error');
            }
            if(data.value == 1){
                $("#type_bid").removeClass('layui-hide');
                $("#type_engin").addClass('layui-hide');
            }
            if(data.value == 2){
                $("#type_bid").addClass('layui-hide');
                $("#type_engin").removeClass('layui-hide');
            }
            if(data.value == 3){
                $("#type_bid").addClass('layui-hide');
                $("#type_engin").addClass('layui-hide');
            }
        });

        form.on('select(youxian)', function(data){
            if(data.value == ''){
                $('#youxian_error').show().text('请选择');
                $('#youxian_error').parent().find('input').addClass('select_error');
            }else{
                $('#youxian_error').hide();
                $('#youxian_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('submit(add)', function(data){
            data.field.flowrelas = get_choose_val('flowrelas');

            var validRes = $("#commentForm").valid();

            if(data.field.type == ''){
                $('#type_error').show().text('请选择');
                $('#type_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#type_error').hide();
                $('#type_error').parent().find('input').removeClass('select_error');

                if(data.field.type == 1){
                    data.field.bidid = get_choose_val('bidid');
                    formValid('bidid');
                    if(data.field.bidid == undefined || !data.field.bidid){
                        validRes = false;
                    }
                }
                if(data.field.type == 2){
                    data.field.enginid = get_choose_val('enginid');
                    formValid('enginid');
                    if(data.field.enginid == undefined || !data.field.enginid){
                        validRes = false;
                    }
                }
            }


            data.field.zhier = tan_tags_getvalue("#zhier", 'user');
            if(!data.field.zhier){
                $("#zhier").parents('.tanxian').addClass('tanerror');
                $('#zhier_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#zhier").parents('.tanxian').removeClass('tanerror');
                $('#zhier_tanerror').text('');
            }

            if(data.field.youxian == ''){
                $('#youxian_error').show().text('请选择');
                $('#youxian_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#youxian_error').hide();
                $('#youxian_error').parent().find('input').removeClass('select_error');
            }

            if(!validRes){return false;}





            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_task_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });


</script>
</body>
</html>
